package com.example.exercises;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int x, y, z, n;
        int sum = 0;
        int[] num = new int[t];
        for (int i = 0; i < t; i++) {//t shuju

            n = sc.nextInt();
            int[] array = new int[n];
            for (int j = 0; j < n; j++) {
                x = sc.nextInt();
                array[j] = x;
            }
            int cardNum = main.getCardNum(array);
            num[i] = cardNum;
        }
        for (int i : num) {
            System.out.println(i);
        }
    }

    public int getCardNum(int[] array) {
        int sum = 0;
        int left = 0, right = 0;
        Map<Integer, Integer> map = new HashMap();
        for (int i : array) {
            if (i == 0) {
                if (map.containsKey(i)) {
                    left++;
                    map.remove(0);
                    sum = Math.max(sum, right - left);
                } else {
                    map.put(0, 0);
                    left++;
                    sum = Math.max(sum, right - left);
                }
                right++;
            } else {
                right++;
                sum = Math.max(sum, right - left);
            }
        }
        return sum;
    }
}

